<?php 
 include_once dirname(__FILE__)."/config.php";
 class piece_joint_principal{
		 protected $_result;
		 protected $_cnn;
		 protected $_id_piece;
		 protected $_id_mail;
		 protected $_piece;
		 protected $_description;
		 public function get_name_table(){ return "piece_joint";}
		 public function get_name_id_piece(){ return "id_piece";}
		 public function get_name_id_mail(){ return "id_mail";}
		 public function get_name_piece(){ return "piece";}
		 public function get_name_description(){ return "description";}
		 public function set_id_piece($parametre){  $this->_id_piece=$parametre;}	
		 public function set_id_mail($parametre){  $this->_id_mail=$parametre;}	
		 public function set_piece($parametre){  $this->_piece=$parametre;}	
		 public function set_description($parametre){  $this->_description=$parametre;}	
		 public function get_result(){ return $this->_result;}
		 public function get_id_piece(){ return $this->_id_piece;}
		 public function get_id_mail(){ return $this->_id_mail;}
		 public function get_piece(){ return $this->_piece;}
		 public function get_description(){ return $this->_description;}
public function __construct(){

		 	$this->_cnn=new databaseconnect();

		 }

 public function INSERT()
{

$sql=" INSERT INTO 
 piece_joint(
			id_mail,
			piece,
			description)
 VALUES(
			'".$this->_id_mail."',
			'".$this->_piece."',
			'".$this->_description."')";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function UPDATE()
{

 $sql="";
if(!empty($this->_id_mail)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
id_mail='".$this->_id_mail."'";
}
if(!empty($this->_piece)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
piece='".$this->_piece."'";
}
if(!empty($this->_description)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
description='".$this->_description."'";
}
$sql="UPDATE 
piece_joint SET 
 ".$sql."
								WHERE id_piece ='".$this->_id_piece."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function DELETE(){

 $sql="DELETE FROM 
piece_joint 
 
									WHERE id_piece ='".$this->_id_piece."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function TRANCATE(){

 $sql="DELETE FROM 
piece_joint ";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function SELECT($constraint="",$pagination="")
{

$sql=" SELECT 
 		id_piece,
		id_mail,
		piece,
		description
 FROM 
 piece_joint";
if($constraint){$sql.=" WHERE 1=1 ".$constraint;}if($pagination){$sql.=$pagination;}
$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}
public function fetch_object(){
$row=mysql_fetch_object($this->_result);
 if($this->_result){
 if($row){
		$this->_id_piece=$row->id_piece;
		$this->_id_mail=$row->id_mail;
		$this->_piece=$row->piece;
		$this->_description=$row->description;
		return $row;
		}else{
					return false;
				}

			}else{
				//echo 'Erreur d\'execution de requette de selection';	
			}
			

		}

}
?>